import { get, post } from '@/utils/request';
import type { ApiResponse } from '@/types/api';
import {SysUser} from "@/types/system";

export interface LoginReq {
  username: string;
  password: string;
  captcha?: string;
}

export interface LoginResp {
  tokenName?: string;
  tokenValue?: string;
  [k: string]: any;
}

export function login(data: LoginReq) {
  return post<ApiResponse<LoginResp>>('/auth/login', data);
}

export function logout() {
  return post<ApiResponse<string>>('/auth/logout');
}

export function me() {
  return get<ApiResponse<SysUser>>('/user/me');
}

export function myMenuTree() {
  return get<ApiResponse<any[]>>('/sysMenu/my/tree');
}

export function myPerms() {
  return get<ApiResponse<{ apiPerms: string[]; webPerms: string[] }>>('/sysMenu/my/perms');
}
